//
//  NewSongTableViewCell.m
//  阿里星球-音乐界面
//
//  Created by mafeng on 16/8/14.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "NewSongTableViewCell.h"
#import "NewSongCollectionViewCell.h"
#import "myViewController.h"
@interface NewSongTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSArray<twodatamodel *> *array;
@end

@implementation NewSongTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.layout = [[UICollectionViewFlowLayout alloc] init];
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([NewSongCollectionViewCell class]) bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"newSongReuse"];
        [self.contentView addSubview:_collectionView];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _collectionView.frame = self.bounds;
    _layout.itemSize = CGSizeMake((self.bounds.size.width - 20) / 3, self.bounds.size.height);
    _layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _layout.minimumLineSpacing = 5;
    _layout.sectionInset = UIEdgeInsetsMake(0, 5, 0, 5);
}

// collectionView的协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 3;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NewSongCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"newSongReuse" forIndexPath:indexPath];
    NSLog(@"🐷%@", _data.data);
    cell.smallData = _data.data[indexPath.row];
    return cell;
}

- (UINavigationController*)naviController {
    
    for (UIView* next = [self superview]; next; next = next.superview) {
        
        UIResponder* nextResponder = [next nextResponder];
        
        if ([nextResponder isKindOfClass:[UINavigationController class]]) {
            
            return (UINavigationController*)nextResponder;
        }
    }
    
    return nil;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    myViewController *vc = [[myViewController alloc]init];
    
    [[self naviController] presentViewController:vc animated:YES completion:nil];
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
